<%= GMap.header %> 

<h1>Add new Expedition</h1>
<%= error_messages_for :expedition %>
<% form_for :expedition, :url => user_expeditions_path(current_user) do |f| -%>



<table width="100%">
	<tr>
		<td width="50%" valign="top">
			<label for="name">Expedition Name</label><br/>
			<%= f.text_field :name %>
		</td>
		<td width="50%" valign="top" class="description">
			
			<label>Sponsor</label><br/>
			<%= text_field_with_auto_complete :sponsor, :name, { :size => 25 }, :skip_style => false, :after_update_element => 
			"function(element,value) " +
			  "{ " +			
			remote_function(:update=>'full_name',:url=>{:action=>:complete_sponsor},:with=>"'id='+element.value") + "}"
			 -%>			

			<div id="sponsor-id">
				<%= f.hidden_field :sponsor_id, :value => "" %>
			</div>
			<%#this will be redrawn ones the sponsor is added%>
			<%= render :partial => "sponsor", :object => nil %>
			
			
		</td>
	</tr>
</table>

<p><label for="target_date">Target Date</label><br/>
	<%= calendar_date_select_tag "expedition[target_date]", @expedition.target_date ? @expedition.target_date.to_s(:date_time12):nil, :embedded => false, :time => true, :buttons => true %>
	<%= error_message_on @expedition, :target_date -%>	

<!-- code between these comments is redundant with stories controller has to be rafactored into a reusable component     -->
<div id="location" class="description">
	<p>
		<table>
			<tr>
				<td>		
					<div id="location_name">
						<%=@geo_location.name%>
					</div>

							<%map = GMap.new("map")%>
							<%
							map.control_init(:large_map => true,:map_type => true)							    
							map.set_map_type_init(GMapType::G_HYBRID_MAP)      							
							map.center_zoom_init([@geo_location.lat,@geo_location.lng],8)  	  						
							marker = GMarker.new([@geo_location.lat, @geo_location.lng], :title => @geo_location.name)  
							map.overlay_init marker							
							%>								
							<%= map.div(:width => 400, :height => 400) %>							
							<%= map.to_html %>

					<%= f.hidden_field :geo_location_id, :value => @geo_location.id %>
					<%= error_message_on @story, :geo_location_id -%>
				</td>
				<td valign="top">
					<label>
						choose from my recent locations:					
					</label>
					<% @recent_geo_locations.each do |recent_location| %>
						<br>
						<%= link_to_remote recent_location.name, :url => {:action => :select_location, :id => recent_location.id } %>
					<%end%>
				</td>
				<td valign="top" class="description">
					<%= link_to image_tag ("add.gif", :border => 0), { :controller => "geo_locations", :action => "new" }%>
					<%= link_to "or add a new location", { :controller => "geo_locations", :action => "new", :return => "expedition" }%>
					<br/>
					<label>
						or search for existing location:
					</label>
					<%= text_field_with_auto_complete :geo_location, :name, { :size => 25 }, :skip_style => false, :after_update_element => 
					"function(element,value) " +
					  "{ " +			
					remote_function(:update=>'full_name',:url=>{:action=>:complete_location},:with=>"'id='+element.value") + "}"
					 -%>
				</td>
			</tr>
		</table>
	</p>
</div>
<!-- code between these comments is redundant with stories controller has to be rafactored into a reusable component     -->

<p class="description"><%= submit_tag 'Create Expedition' %><%= link_to 'back', user_path(current_user)%></p>
<% end -%>
